/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.icanci.design.builder.prototypepattern.demo02;

import java.util.ArrayList;
import java.util.List;

/**
 * jdk 的clone方法，浅克隆
 *  - 下面的例子中，List 重写了clone方法，用自己进行赋值的方法进行重写，达到了效果
 *  - 但是如果对象太过复杂，那么就不能这样去做 维护也很麻烦
 * @author icanci
 * @date Created in 2021/07/15 08:13
 * @version 1.0
 */
public class Prototype02 {
    public static void main(String[] args) {
        List<String> addressList = new ArrayList<>();
        addressList.add("icanci1");
        addressList.add("icanci2");
        addressList.add("icanci3");
        addressList.add("icanci4");
        ClassB classB = new ClassB();
        classB.setId("1");
        classB.setAddress(addressList);

        ClassB copy = (ClassB) classB.clone();

        classB.setId("2");
        addressList.add("xxxx");

        System.out.println(classB);
        System.out.println(copy);
    }
}
